<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
	<head>
		<title>封条管理及验证系统--通讯录管理</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
	</head>
		<%@ include file="/comm.jsp"%>
<script language="JavaScript">
	var contactList=null;
	var selUserId=null;
	var selCompanyName=null;
	$(document).ready(function(){
		loadContact();
	});
	
	function loadContact(){
		var params = {};
		$.ajax({type: "POST",
		       url: "ajaxContact_loadContact",
		       data: params,
		       async: false,   
		       success: function(responseMsg){
		        var data=eval('('+responseMsg+')');
				contactList = eval(data.contactList);
				var groupHtml="";
				for(var i=0;i<contactList.length;i++){
					var group=contactList[i].group;
					groupHtml +="<a href='#' onclick=\"viewMember("+group.id+");\">"+group.groupName+"("+group.count+")</a><br/>";
				}
				$("#spanGroups").html(groupHtml);
				viewMember(0);//显示所有
			  }
			},"json");
	}
	
	function viewMember(groupId) {
		for(var i=0;i<contactList.length;i++){
			var group=contactList[i].group;
			if(group.id==groupId){
				var memberList = contactList[i].memberList;   
				if(memberList.length==0){   
				    $("#tb_memberList").html("<tr><td>没有联系人在分组中</td></tr>");
				    return;
				}
				var result="<thead>"
				result += "<tr class='tr_title'>";
				result += "<td align='center'></td>";
				result += "<td width='110'>账户代码</td>";
				result += "<td >账户名称</td>";
				result += "<td >姓名</td>";
				result += "</tr>";
				result += "</thead>";
				result += "<tbody>";
				//这里的order[i]就相当于list中的order,起属性也是一一对应的   
				for(var j=0;j<memberList.length;j++) {   
				    result += "<tr>";   
				    result += "<td align='center' width='30'><input name='chkSon' id='"+memberList[j].id+"' type='checkbox' value='"+memberList[j].id+"' onclick=\"selectRow("+memberList[j].id+",'"+memberList[j].relateUserid+"','"+memberList[j].relateCompanyName+"')\"></td>";
				    result += "<td>"+memberList[j].relateUserid+"</td>";   
				    result += "<td>"+memberList[j].relateCompanyName+"</td>";
				    result += "<td>"+memberList[j].relateName+"</td>";
				    result += "</tr>";   
				}
				result += "</tbody>";
				$("#tb_memberList").html(result);
				break;
			}
		}
	}
	
	function selectRow(memberId,userId,companyName){
		var arrSon = document.getElementsByName('chkSon');
	 	var curChkbox = document.getElementById(memberId);
	 	if(curChkbox.checked==true){
		 	for(var i=0; i<arrSon.length; i++) {
		 		if(arrSon[i].value != memberId){
		     		arrSon[i].checked = false;
		     	}
		 	}
		 	curChkbox.checked=true;
		 	selUserId=userId;
			selCompanyName=companyName;
	 	}else{
	 		selUserId='';
			selCompanyName='';
		}
	}
	
	function selectOK()
	{
		if(selUserId=='' || selUserId==null)
		{
			alert("请选择收货方账户");
			return;
		}
		var obj=new Array(selUserId,selCompanyName);
		window.returnValue = obj;
		window.close();
	}
	
</script>
	
	<body>
		<s:form name="formpage" namespace="/seal">
			<div align="center">
			<%@ include file="/messages.jsp"%>
			<table width="660" align="left">
				<tr>
					<td valign="top" rowspan="2" width="150">
						<span id="spanGroups">
						</span>
					</td>
					<td valign="top">
						<table align="center" width="100%" class="tb_datalist" id="tb_memberList">
						</table>
					</td>
				</tr>
				<tr>
					<td align="center">
						<input type="button" name="Submit" id="ok" class="button" value="确 定2" onclick="javascript:selectOK();"/>&nbsp;&nbsp;
						<input type="button" name="Return" id="retBtn" class="button" value="返 回" onclick="javascript:window.close();" />
					</td>
				</tr>
			</table>
		</s:form>
	</body>
</html>
